export default function (date: Date, format: string = 'yyyy-MM-dd HH:mm:ss'): string {
  const map = {
    'yyyy': date.getFullYear().toString(),
    'M': String(date.getMonth() + 1),
    'MM': String(date.getMonth() + 1).padStart(2, '0'),
    'd': String(date.getDate()),
    'dd': String(date.getDate()).padStart(2, '0'),
    'H': String(date.getHours()),
    'HH': String(date.getHours()).padStart(2, '0'),
    'm': String(date.getMinutes()),
    'mm': String(date.getMinutes()).padStart(2, '0'),
    's': String(date.getSeconds()),
    'ss': String(date.getSeconds()).padStart(2, '0'),
  };

  return format.replace(/yyyy|MM|M|dd|d|HH|H|mm|m|ss|s/g, (match) => {
    return map[match as keyof typeof map] || match;
  });
};